//
//  HelpScene.m
//  ShoutBoss
//
//  Created by Yin supmarboro on 09-6-24.
//  Copyright 2009 JW. All rights reserved.
//

#import "HelpScene.h"
#import "HelpBackGround.h"
#import "MainMenuScene.h"


@implementation HelpScene

-(id) init
{
	self = [super init];
	if(self != nil){
		//LogoScene 初始化工作
		HelpLayer * logoLayer =[HelpLayer node];	
		[self addChild: logoLayer];
	}
	
	return self;
}

@end

@implementation HelpLayer
-(id) init
{
	if( ( self=[super init] ))
	{
		//启动Touch
		isTouchEnabled = YES;
		
		//LogoLayer 初始化工作
		CGSize s = [[Director sharedDirector] winSize];
		
		HelpBackGround* background = [HelpBackGround node];
		[self addChild:background];
		[background setPosition: ccp(s.width/2, s.height/2)];
		
		//标签
		label1 = [Label labelWithString:@"Help View" fontName:@"Courier" fontSize:32];
		label1.position = ccp(480-120, 320-32);
		[self addChild:label1];
		
		 //TextView
		 ctrlLayer = [HelpTextViewLayer node];
		 [self addChild:ctrlLayer];
		 
		//RetunMenu
		[MenuItemFont setFontName: @"Marker Felt"];
		[MenuItemFont setFontSize:34];
		MenuItem *itemReturn = [MenuItemFont itemFromString:@"Done" target:self selector:@selector(menuReturnCallBack:)];		
		Menu *menuReturn = [Menu menuWithItems:
							itemReturn, nil];
		[menuReturn setPosition:ccp(480-48, 32)];
		
		[self addChild: menuReturn];
	}	
	return self;
}

-(void) menuReturnCallBack: (id) sender
{
	// 切换到MainMenu
	MainMenuScene* mainMenuScene = [MainMenuScene node];
	[[Director sharedDirector] replaceScene:mainMenuScene];
}

- (void) dealloc
{
	[super dealloc];
}

@end

@implementation HelpTextViewLayer
-(id) init
{	
	self = [super init]; 
	
	if (self != nil){
		//very important, need set same size or larger than subviews.
		[self setFrame: CGRectMake(0, 0, 401, 251)];
		[self setPosition: ccp(150, 245)]; 
		
		/////////////////////////////////////////////////////////////////////////////////////////////////////
		/*UITextField *view = [[UITextField alloc] initWithFrame: CGRectMake(100, 228, 220, 28)];
		 view.transform = CGAffineTransformMakeRotation(M_PI * (90.0 / 180.0)); // rotate for landscape
		 view.backgroundColor = [UIColor clearColor];
		 view.borderStyle = UITextBorderStyleRoundedRect;
		 view.delegate = self; // set this layer as the UITextFieldDelegate
		 view.returnKeyType = UIReturnKeyDone; // add the 'done' key to the keyboard
		 view.autocorrectionType = UITextAutocorrectionTypeNo; // switch of auto correction
		 view.autocapitalizationType = UITextAutocapitalizationTypeWords;*/
		 
		//////////////////////////////////////////////////////////////////////////////////////////////////////
		/*
		 contentTextView =  [[UITextView alloc] initWithFrame:CGRectMake(0,0, 400, 250)]; 
		 [contentTextView setTransform:CGAffineTransformMakeRotation(1.569)];
		
		 contentTextView.font = [UIFont systemFontOfSize:12.0]; 
		 contentTextView.textColor = [UIColor whiteColor];
		 contentTextView.backgroundColor = [UIColor clearColor];
		 contentTextView.textAlignment = UITextAlignmentLeft;
		 contentTextView.editable = FALSE;
		 
		NSString *Content = [[NSString alloc] initWithString:@"ontentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContentAboutContent"];
		
		contentTextView.text = NSLocalizedStringFromTable(Content ,@"resource",nil);
		
		[self addChild: contentTextView];
		 */
		contentTextView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0, 400, 250)]; 
		[contentTextView setTransform:CGAffineTransformMakeRotation(1.569)];
		
		NSString *path = [[NSBundle mainBundle] pathForResource:@"Help" ofType:@"html"];
		NSFileHandle *readHandle = [NSFileHandle fileHandleForReadingAtPath:path];
		
		NSString *htmlString = [[NSString alloc] initWithData: 
								[readHandle readDataToEndOfFile] encoding:NSUTF8StringEncoding];
		
		// to make html content transparent to its parent view -
		// 1) set the webview's backgroundColor property to [UIColor clearColor]
		// 2) use the content in the html: <body style="background-color: transparent">
		// 3) opaque property set to NO
		//
		contentTextView.opaque = NO;
		contentTextView.backgroundColor = [UIColor clearColor];
		[contentTextView loadHTMLString:htmlString baseURL:nil];
		[htmlString release];
		
		[self addChild: contentTextView];
		
	}
	return self;
} 

-(void) dealloc
{
	//need manual release subviews
	[contentTextView removeFromSuperview];
	[contentTextView release];
	[super dealloc];
} 

@end
